package com.huawei.appgallery.appcomment.ui;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.huawei.appgallery.appcomment.impl.bean.GetReplyResBean;
import com.huawei.appgallery.appcomment.impl.bean.GetReplyResBean.ReplyComment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b;
import com.huawei.appgallery.foundation.ui.framework.widget.PullUpListView.a;
import com.huawei.appgallery.jsonkit.api.JsonBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.fastengine.fastview.startFastappEngine.bean.RpkInfo;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import o.azb;
import o.bcb;
import o.bcg;
import o.bcg.c;
import o.bcg.d;
import o.bcg.h;
import o.bdf;
import o.bdl;
import o.bdm.e;
import o.bds;
import o.bea;
import o.cdh;
import o.cip;
import o.cjo;
import o.ckv;
import o.cvt;
import o.ll;

public class AppReplyFragment extends TaskFragment<cjo> implements a {
    private boolean ʹ = false;
    private bdl ʻˋ = null;
    private Object ʻᐝ = new Object();
    private String ʼ;
    private BroadcastReceiver ʼˊ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ AppReplyFragment ॱ;

        {
            this.ॱ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            SafeIntent safeIntent = new SafeIntent(intent);
            if ("com.huawei.appmarket.service.broadcast.CommentReplyAdded".equals(safeIntent.getAction())) {
                ˊ(safeIntent);
            } else if ("com.huawei.appmarket.service.broadcast.Approved".equals(safeIntent.getAction())) {
                this.ॱ.ˋ(safeIntent, "ACTION_PARAM_COMMENT_APPROVED");
            } else if ("com.huawei.appmarket.service.broadcast.ReplyFilter".equals(safeIntent.getAction())) {
                bcb.ˋ.ˋ("AppReplyFragment", "Switching order");
                this.ॱ.ʼˋ = safeIntent.getIntExtra("com.huawei.appmarket.service.broadcast.ReplyFilter", 1);
                this.ॱ.ʻˋ.ˎ(1);
                this.ॱ.ʿˊ();
            } else if ("com.huawei.appmarket.service.broadcast.CommentCollect".equals(safeIntent.getAction())) {
                e eVar = (e) safeIntent.getSerializableExtra("ACTION_PARAM_COMMENT_CANCEL_COLLECT_TYPE_COMMENTID");
                if (this.ॱ.ˋ != null) {
                    this.ॱ.ˋ.ˎ(eVar);
                }
            } else if ("com.huawei.appmarket.service.broadcast.Approved.reply".equals(safeIntent.getAction())) {
                Serializable serializableExtra = safeIntent.getSerializableExtra("ACTION_PARAM_COMMENT_APPROVED_REPLY");
                if (serializableExtra instanceof e) {
                    this.ॱ.ˋ((e) serializableExtra);
                }
            } else if ("com.huawei.appmarket.service.broadcast.Dissed".equals(safeIntent.getAction())) {
                this.ॱ.ˋ(safeIntent, "ACTION_PARAM_COMMENT_DISSED");
            } else if ("com.huawei.appmarket.service.broadcast.CommentDeleted".equals(safeIntent.getAction())) {
                this.ॱ.ॱˋ().finish();
            } else if ("com.huawei.appmarket.service.broadcast.ReplyDeleted".equals(safeIntent.getAction())) {
                ˋ(safeIntent);
            }
        }

        private void ˋ(SafeIntent safeIntent) {
            this.ॱ.ॱ(safeIntent.getStringExtra("ACTION_PARAM_REPLY_DEL_TYPE_REPLYID"));
        }

        private void ˊ(SafeIntent safeIntent) {
            synchronized (this.ॱ.ʻᐝ) {
                String stringExtra = safeIntent.getStringExtra("ACTION_PARAM_COMMENT_REPLY_ADDED_TYPE_COMMENTID");
                String stringExtra2 = safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_APPID");
                if (!(TextUtils.isEmpty(this.ॱ.ˎ) || !this.ॱ.ˎ.equals(stringExtra) || TextUtils.isEmpty(this.ॱ.ᐝ) || !this.ॱ.ᐝ.equals(stringExtra2) || this.ॱ.ʻˋ == null || this.ॱ.ʹ)) {
                    this.ॱ.ʽˊ();
                    this.ॱ.ʻˋ.ˏ(false);
                    this.ॱ.ʻˋ.ᐝ();
                    this.ॱ.ʽᐝ();
                }
            }
        }
    };
    private int ʼˋ = 1;
    private List<JsonBean> ʽ = new ArrayList();
    private ViewGroup ˊ;
    private bea ˋ;
    private String ˎ;
    private cip ˏ;
    private View ॱ;
    private int ॱॱ;
    private String ᐝ;
    private int ﹳ = -1;
    private int ﾞ;
    private boolean ﾟ = false;

    public void ˋ(e eVar) {
        if (this.ʻˋ != null) {
            for (int i = 0; i < this.ʻˋ.ॱ(); i++) {
                ReplyComment replyComment = (ReplyComment) this.ʻˋ.ʻ().get(i);
                if (replyComment.ॱ().equals(eVar.ॱ())) {
                    replyComment.ˋ(replyComment.ॱˊ() + eVar.ˋ());
                    replyComment.ˏ(eVar.ॱॱ());
                    break;
                }
            }
            if (this.ˋ != null) {
                this.ˋ.ʽ();
            }
        }
    }

    public void ॱ(String str) {
        List<ReplyComment> arrayList = new ArrayList();
        arrayList.addAll(this.ʻˋ.ʻ());
        if (arrayList.size() > 0) {
            for (ReplyComment replyComment : arrayList) {
                if (!TextUtils.isEmpty(replyComment.ॱ()) && replyComment.ॱ().equals(str)) {
                    this.ʻˋ.ʻ().remove(replyComment);
                    break;
                }
            }
            if (this.ˋ != null) {
                this.ˋ.ʽ();
            }
        }
    }

    private void ˋ(SafeIntent safeIntent, String str) {
        Serializable serializableExtra = safeIntent.getSerializableExtra(str);
        if (serializableExtra instanceof e) {
            e eVar = (e) serializableExtra;
            if (this.ˋ != null) {
                this.ˋ.ˋ(eVar);
            }
        }
    }

    public void ˏ(Bundle bundle) {
        Bundle ˊॱ = ˊॱ();
        this.ᐝ = ˊॱ.getString(RpkInfo.APPID);
        this.ˎ = ˊॱ.getString("commentid");
        this.ʼ = ˊॱ.getString("user_name");
        this.ॱॱ = ˊॱ.getInt("is_approved");
        this.ﾞ = ˊॱ.getInt("is_dissed");
        this.ﹳ = ˊॱ.getInt("position");
        this.ﾟ = ˊॱ.getBoolean("show_all_comment");
        this.ʽ.add(new ReplyComment());
        ॱˋ(true);
        super.ˏ(bundle);
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        IntentFilter intentFilter = new IntentFilter("com.huawei.appmarket.service.broadcast.CommentReplyAdded");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.Approved");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.Dissed");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.ReplyFilter");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.CommentCollect");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.Approved.reply");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.CommentDeleted");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.ReplyDeleted");
        ll.ˏ(ॱˋ()).ˏ(this.ʼˊ, intentFilter);
        this.ˊ = viewGroup;
        ॱˋ().setTitle(ˊ(h.ˌॱ));
        this.ˋ = new bea();
        this.ˋ.ॱ((TaskFragment) this);
        this.ˋ.ˏ(this.ʼˋ);
        this.ˋ.ॱ(this.ˎ);
        this.ˋ.ˎ(this.ʼ);
        this.ˋ.ˏ(this.ᐝ);
        this.ˋ.ˋ(this.ﾟ);
        ((AppCommentReplyActivity) ॱˋ()).ˊ(this.ˋ);
        ((AppCommentReplyActivity) ॱˋ()).ˏ(this.ˋ);
        if (this.ʻˋ == null) {
            this.ʻˋ = new bdl();
        }
        this.ॱ = this.ˋ.ˏ(layoutInflater, viewGroup, bundle);
        this.ˋ.ˋ(this.ʽ);
        if (this.ʻˋ.ˏ() == null) {
            ʽˊ();
            ॱˋ(false);
            ʿˊ();
        } else if (this.ˏ != null) {
            this.ˏ.ˎ(this.ॱ.findViewById(bcg.e.ߵ));
            this.ˏ.ॱ(0);
        }
        return this.ॱ;
    }

    public void ˋ(TaskFragment taskFragment, List<cvt> list) {
        bdf o_bdf = new bdf();
        o_bdf.ˊ(this.ˎ);
        o_bdf.ˋ(30);
        o_bdf.ˏ(this.ʻˋ.ˋ());
        o_bdf.ˎ(this.ʼˋ);
        o_bdf.setServiceType_(cdh.ˎ(ॱˋ()));
        list.add(o_bdf);
    }

    public boolean ˊ(TaskFragment taskFragment, b bVar) {
        ResponseBean responseBean = (GetReplyResBean) bVar.ˋ;
        ʾॱ();
        if (bVar.ˋ.getResponseCode() != 0) {
            if (this.ˋ != null) {
                this.ˋ.ˏ(false, bVar.ˊ, responseBean);
            }
            if (this.ˏ != null) {
                this.ˏ.ˏ(bVar.ˋ.getResponseCode(), true);
            } else if (bVar.ˋ.getResponseCode() == 3) {
                ckv.ˎ(ॱˋ().getString(h.ᐝʽ), 0);
            }
        } else {
            int rtnCode_ = bVar.ˋ.getRtnCode_();
            if (rtnCode_ != 0) {
                ˋ(rtnCode_);
            } else {
                if (this.ʻˋ.ˋ() == 1) {
                    this.ʻˋ.ᐝ();
                }
                if (responseBean.ˏ() != null) {
                    responseBean.ˏ().ˋ(this.ॱॱ);
                    responseBean.ˏ().ॱ(this.ﾞ);
                    responseBean.ˏ().ᐝ(this.ﹳ);
                    responseBean.ˏ().ˋ(this.ᐝ);
                    this.ʻˋ.ˋ(responseBean);
                    ॱˋ(true);
                } else if (this.ˊ != null) {
                    View inflate = LayoutInflater.from(this.ˊ.getContext()).inflate(d.ॱॱ, this.ˊ, false);
                    azb.ˏ(inflate);
                    this.ˊ.addView(inflate);
                }
                if (this.ˋ != null) {
                    this.ˋ.ˏ(true, bVar.ˊ, responseBean);
                }
                rtnCode_ = this.ʻˋ.ˋ() + 1;
                this.ʻˋ.ˎ(rtnCode_);
                if (rtnCode_ > responseBean.ॱ()) {
                    this.ʻˋ.ˏ(false);
                } else {
                    this.ʻˋ.ˏ(true);
                }
                this.ᶥॱ = null;
            }
        }
        return false;
    }

    private void ˋ(int i) {
        View inflate = LayoutInflater.from(this.ˊ.getContext()).inflate(d.ॱॱ, this.ˊ, false);
        azb.ˏ(inflate);
        ImageView imageView = (ImageView) inflate.findViewById(bcg.e.ʼॱ);
        TextView textView = (TextView) inflate.findViewById(bcg.e.ʽॱ);
        if (i == 8) {
            imageView.setImageResource(c.ʻॱ);
            textView.setText(ᐝॱ().getString(h.ـ));
        } else if (i == 9) {
            imageView.setImageResource(c.ʻॱ);
            textView.setText(ᐝॱ().getString(h.ॱॱ));
        } else if (i == 11) {
            imageView.setImageResource(c.ʻॱ);
            textView.setText(ᐝॱ().getString(h.ˏ));
        } else if (i == 12) {
            imageView.setImageResource(c.ʻॱ);
            textView.setText(ᐝॱ().getString(h.ᐝ));
        }
        if (this.ˊ != null) {
            this.ˊ.addView(inflate);
        }
    }

    public bds ॱ() {
        return this.ʻˋ;
    }

    public void ʽᐝ() {
        ʿˊ();
    }

    public void ʼᐝ() {
        this.ˋ.ˏ();
        ʿˊ();
    }

    public void ˊʼ() {
    }

    public void ʿॱ() {
    }

    private void ʽˊ() {
        this.ʹ = true;
        if (this.ˏ == null) {
            this.ˏ = new cip();
            this.ˏ.ˎ(this.ॱ.findViewById(bcg.e.ߺ));
            this.ˏ.ˋ(new OnClickListener(this) {
                final /* synthetic */ AppReplyFragment ˏ;

                {
                    this.ˏ = r1;
                }

                public void onClick(View view) {
                    this.ˏ.ʿˊ();
                }
            });
        }
        this.ˏ.ॱ(0);
    }

    private void ʾॱ() {
        this.ʹ = false;
        if (this.ˏ != null) {
            this.ˏ.ॱ(8);
            this.ˏ = null;
        }
    }

    public void ᐝ() {
        try {
            ll.ˏ(ॱˋ()).ˋ(this.ʼˊ);
        } catch (Throwable e) {
            bcb.ˋ.ˊ("AppReplyFragment", "onDestroyView error", e);
        }
        if (this.ˋ != null) {
            try {
                this.ˋ.ˋ();
            } catch (Throwable e2) {
                bcb.ˋ.ˊ("AppReplyFragment", "onDestroyView error", e2);
            }
        }
        super.ᐝ();
    }

    public void ˈॱ() {
    }
}
